﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using VPBS.Common;

namespace VPBS.SqlClient.DAL
{
    public class TnPlusVCustomerInfoDAL
    {
        /// <summary>
        /// Lay thong tin ve tai san cua khach hang
        /// </summary>
        /// <param ></param>
        /// <returns>DataSet Get_VCustomerInfo</returns>
        public static DataTable Get_VCustomerInfo(string AccountNo, string IdCommon)
        {
            try
            {
                string command =
                    @"select * from VCustomerInfo where AccountNo='" + AccountNo + "' and IdCommon='" + IdCommon + "'";

                DataSet ds = SqlHelper.ExecuteDataset(ConnectStringHelper.TnPlusConnectionString, CommandType.Text,
                                                      command);
                if (ds != null && ds.Tables.Count > 0)
                    return ds.Tables[0];
                return new DataTable();
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(Get_VCustomerInfo), ex);
                return new DataTable();
            }
        }

        /// <summary>
        /// Xoa di du lieu qua khu cua cac bang: CallSMS, CashToday, DebtToday, PortfolioToday
        /// </summary>
        /// <param ></param>
        /// <returns>Void</returns>
        public static void DeleteSMSSender()
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectStringHelper.TnPlusConnectionString, CommandType.StoredProcedure,
                                          "SDeleteSMSSender");
                return;
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(DeleteSMSSender), ex);
                return;
            }
        }

        /// <summary>
        /// Lay IdCommon cua lan transfer cuoi cung
        /// </summary>
        /// <param ></param>
        /// <returns>IdCommon</returns>
        public static string Get_LastIdCommon()
        {
            try
            {
                string command = @"select top(1) IdCommon from CashToday where datediff(day,Postdate,getdate())=0 order by Postdate desc";
                DataSet ds = SqlHelper.ExecuteDataset(ConnectStringHelper.TnPlusConnectionString, CommandType.Text,
                                                      command);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                    return ds.Tables[0].Rows[0][0].ToString();
                return "";
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(Get_LastIdCommon), ex);
                return "";
            }
        }

        /// <summary>
        /// Lay PortfolioToday theo IdCommon
        /// </summary>
        /// <param value="IdCommon" ></param>
        /// <returns>DataTable Get_PortfolioToday_With_IdCommon</returns>
        public static DataTable Get_PortfolioToday_With_IdCommon(string IdCommon)
        {
            try
            {
                string command =
                    @"select * from PortfolioToday where datediff(day,PostDate,Getdate())=0 and IdCommon='" + IdCommon +
                    "'";

                DataSet ds = SqlHelper.ExecuteDataset(ConnectStringHelper.TnPlusConnectionString, CommandType.Text,
                                                      command);
                if (ds != null && ds.Tables.Count > 0)
                    return ds.Tables[0];
                return new DataTable();
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(Get_PortfolioToday_With_IdCommon), ex);
                return new DataTable();
            }
        }

        /// <summary>
        /// Lay CashToday theo IdCommon
        /// </summary>
        /// <param value="IdCommon" ></param>
        /// <returns>DataTable Get_CashToday_With_IdCommon</returns>
        public static DataTable Get_CashToday_With_IdCommon(string IdCommon)
        {
            try
            {
                string command =
                    @"select * from CashToday where datediff(day,PostDate,Getdate())=0 and IdCommon='" + IdCommon +
                    "'";

                DataSet ds = SqlHelper.ExecuteDataset(ConnectStringHelper.TnPlusConnectionString, CommandType.Text,
                                                      command);
                if (ds != null && ds.Tables.Count > 0)
                    return ds.Tables[0];
                return new DataTable();
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(Get_CashToday_With_IdCommon), ex);
                return new DataTable();
            }
        }

        /// <summary>
        /// Lay DebtToday theo IdCommon
        /// </summary>
        /// <param value="IdCommon" ></param>
        /// <returns>DataTable Get_DebtToday_With_IdCommon</returns>
        public static DataTable Get_DebtToday_With_IdCommon(string IdCommon)
        {
            try
            {
                string command =
                    @"select * from DebtToday where datediff(day,PostDate,Getdate())=0 and IdCommon='" + IdCommon +
                    "'";

                DataSet ds = SqlHelper.ExecuteDataset(ConnectStringHelper.TnPlusConnectionString, CommandType.Text,
                                                      command);
                if (ds != null && ds.Tables.Count > 0)
                    return ds.Tables[0];
                return new DataTable();
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(Get_DebtToday_With_IdCommon), ex);
                return new DataTable();
            }
        }
    }
}
